Skip to content

Phase 2: Dashboard frontend with public metrics and community tabs#140

Merged
neuromechanist merged 6 commits into
feature/issue-132-epic-community-dashboardfrom
feature/issue-135-phase2-frontend
Feb 3, 2026
Merged

Phase 2: Dashboard frontend with public metrics and community tabs#140
neuromechanist merged 6 commits into
feature/issue-132-epic-community-dashboardfrom
feature/issue-135-phase2-frontend

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

  • Add public metrics API endpoints that expose request counts and error rates without authentication (no tokens, costs, or model info)
  • Create standalone static dashboard (dashboard/index.html) deployed to Cloudflare Pages at osa-dash.pages.dev
  • Dynamic community tab bar populated from the API; new communities appear automatically
  • Client-side routing: / for aggregate overview, /{community} for per-community detail
  • Chart.js charts for usage over time and top tools
  • Admin section (hidden by default) unlockable with API key for token/cost data
  • CI workflow for Cloudflare Pages deployment with PR preview URLs

Closes #135

New files

  • src/api/routers/metrics_public.py - Global public overview endpoint
  • src/metrics/queries.py - 3 public query functions (overview, community summary, usage stats)
  • dashboard/index.html - Standalone static dashboard with Chart.js
  • dashboard/_redirects - Cloudflare Pages SPA routing
  • .github/workflows/deploy-dashboard.yml - CI for dashboard deploys
  • tests/test_api/test_metrics_public.py - 17 tests for public endpoints
  • tests/test_api/test_dashboard.py - 15 tests for static HTML content

Modified files

  • src/api/routers/community.py - Added per-community /metrics/public and /metrics/public/usage endpoints
  • src/api/main.py - Registered metrics_public_router
  • src/api/routers/__init__.py - Exported new router

Test plan

  • All 32 new tests pass (test_metrics_public.py + test_dashboard.py)
  • Public endpoints return no sensitive data (tokens, costs, models)
  • Admin endpoints still require auth
  • Dashboard HTML contains expected structure, Chart.js CDN, routing functions
  • Pre-commit hooks pass (ruff, format)
  • Manual: verify dashboard loads at preview URL
  • Manual: verify community tabs populate dynamically
  • Manual: verify admin unlock shows token/cost charts

- Add public query functions (no tokens/costs/models exposed)
- Create /metrics/public/* endpoints (no auth required)
- Build /dashboard page with Chart.js, community tabs, admin unlock
- Register new routers in main.py
- Add tests for public endpoints and dashboard page (28 new tests)
- Move per-community public metrics to community router
  (/{community_id}/metrics/public, /{community_id}/metrics/public/usage)
- Keep only global /metrics/public/overview in metrics_public router
- Remove FastAPI dashboard router
- Add dashboard/ as standalone static site for Cloudflare Pages:
  / = aggregate overview, /{community} = community detail
- Client-side routing with configurable API base URL
- Add _redirects for Cloudflare Pages SPA routing
- Update tests for new route structure
Deploys dashboard/ to osa-dash.pages.dev via wrangler.
Same pattern as existing deploy-pages.yml for the demo widget:
- main -> osa-dash.pages.dev (production)
- develop -> develop.osa-dash.pages.dev
- PRs -> {branch}.osa-dash.pages.dev with preview URL comment
Tabs are populated from /metrics/public/overview API so new
communities appear automatically. Navigation uses simple links
(All -> /, community -> /{id}) with active tab highlighting.
@github-actions

github-actions Bot commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Dashboard Preview

Name Link
Preview URL https://feature-issue-135-phase2-fro.osa-dash.pages.dev
Branch feature/issue-135-phase2-frontend
Commit 0e09a01

This preview will be updated automatically when you push new commits.

- Fix XSS: add escapeHtml() helper, sanitize all innerHTML interpolations,
  use encodeURIComponent() for URL path segments
- Move get_metrics_connection() inside try blocks in all metrics endpoints
- Add console.error/warn to all JavaScript catch blocks (no silent failures)
- Improve admin section UX: defer visibility until data loads successfully
- Extract shared helpers in queries.py (_count_tools, _validate_period)
- Add test classes: TestPublicAdminBoundary, TestEmptyDatabase,
  TestCommunityMetricsValues with dynamic community cross-checks
- Fix admin boundary tests to use auth_env fixture with test API key
- Fix single-quote XSS in onclick handlers: use encodeURIComponent
  for communityId in changePeriod calls, decode in changePeriod
- Validate health status against known values instead of escapeHtml
- Add console.warn to sync/health .catch() blocks
- Add console.error to loadCommunityView catch block
- Add auth-enabled tests proving public endpoints stay accessible
  when REQUIRE_API_AUTH=true (core security contract)
- Add metrics_connection() context manager in db.py; simplify all
  endpoint handlers from nested try/try/finally to with-statement
- Use tuple unpacking in _count_tools for clarity
@neuromechanist neuromechanist merged commit 0253e54 into feature/issue-132-epic-community-dashboard Feb 3, 2026
4 checks passed
@neuromechanist neuromechanist deleted the feature/issue-135-phase2-frontend branch February 5, 2026 13:34
@neuromechanist neuromechanist linked an issue Feb 5, 2026 that may be closed by this pull request
4 tasks
@neuromechanist neuromechanist mentioned this pull request Feb 7, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Community dashboard with metrics, usage stats, and sync status

1 participant